home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / test / test_codecencodings_jp.py < prev    next >
Text File  |  2005-10-18  |  4KB  |  113 lines

  1. #!/usr/bin/env python
  2. #
  3. # test_codecencodings_jp.py
  4. #   Codec encoding tests for Japanese encodings.
  5. #
  6. # $CJKCodecs: test_codecencodings_jp.py,v 1.3 2004/06/19 06:09:55 perky Exp $
  7.  
  8. from test import test_support
  9. from test import test_multibytecodec_support
  10. import unittest
  11.  
  12. class Test_CP932(test_multibytecodec_support.TestBase, unittest.TestCase):
  13.     encoding = 'cp932'
  14.     tstring = test_multibytecodec_support.load_teststring('shift_jis')
  15.     codectests = (
  16.         # invalid bytes
  17.         ("abc\x81\x00\x81\x00\x82\x84", "strict",  None),
  18.         ("abc\xf8", "strict",  None),
  19.         ("abc\x81\x00\x82\x84", "replace", u"abc\ufffd\uff44"),
  20.         ("abc\x81\x00\x82\x84\x88", "replace", u"abc\ufffd\uff44\ufffd"),
  21.         ("abc\x81\x00\x82\x84", "ignore",  u"abc\uff44"),
  22.         # sjis vs cp932
  23.         ("\\\x7e", "replace", u"\\\x7e"),
  24.         ("\x81\x5f\x81\x61\x81\x7c", "replace", u"\uff3c\u2225\uff0d"),
  25.     )
  26.  
  27. class Test_EUC_JISX0213(test_multibytecodec_support.TestBase,
  28.                         unittest.TestCase):
  29.     encoding = 'euc_jisx0213'
  30.     tstring = test_multibytecodec_support.load_teststring('euc_jisx0213')
  31.     codectests = (
  32.         # invalid bytes
  33.         ("abc\x80\x80\xc1\xc4", "strict",  None),
  34.         ("abc\xc8", "strict",  None),
  35.         ("abc\x80\x80\xc1\xc4", "replace", u"abc\ufffd\u7956"),
  36.         ("abc\x80\x80\xc1\xc4\xc8", "replace", u"abc\ufffd\u7956\ufffd"),
  37.         ("abc\x80\x80\xc1\xc4", "ignore",  u"abc\u7956"),
  38.         ("abc\x8f\x83\x83", "replace", u"abc\ufffd"),
  39.         ("\xc1\x64", "strict", None),
  40.         ("\xa1\xc0", "strict", u"\uff3c"),
  41.     )
  42.     xmlcharnametest = (
  43.         u"\xab\u211c\xbb = \u2329\u1234\u232a",
  44.         "\xa9\xa8ℜ\xa9\xb2 = ⟨ሴ⟩"
  45.     )
  46.  
  47. eucjp_commontests = (
  48.     ("abc\x80\x80\xc1\xc4", "strict",  None),
  49.     ("abc\xc8", "strict",  None),
  50.     ("abc\x80\x80\xc1\xc4", "replace", u"abc\ufffd\u7956"),
  51.     ("abc\x80\x80\xc1\xc4\xc8", "replace", u"abc\ufffd\u7956\ufffd"),
  52.     ("abc\x80\x80\xc1\xc4", "ignore",  u"abc\u7956"),
  53.     ("abc\x8f\x83\x83", "replace", u"abc\ufffd"),
  54.     ("\xc1\x64", "strict", None),
  55. )
  56.  
  57. class Test_EUC_JP_COMPAT(test_multibytecodec_support.TestBase,
  58.                          unittest.TestCase):
  59.     encoding = 'euc_jp'
  60.     tstring = test_multibytecodec_support.load_teststring('euc_jp')
  61.     codectests = eucjp_commontests + (
  62.         ("\xa1\xc0\\", "strict", u"\uff3c\\"),
  63.         (u"\xa5", "strict", "\x5c"),
  64.         (u"\u203e", "strict", "\x7e"),
  65.     )
  66.  
  67. shiftjis_commonenctests = (
  68.     ("abc\x80\x80\x82\x84", "strict",  None),
  69.     ("abc\xf8", "strict",  None),
  70.     ("abc\x80\x80\x82\x84", "replace", u"abc\ufffd\uff44"),
  71.     ("abc\x80\x80\x82\x84\x88", "replace", u"abc\ufffd\uff44\ufffd"),
  72.     ("abc\x80\x80\x82\x84def", "ignore",  u"abc\uff44def"),
  73. )
  74.  
  75. class Test_SJIS_COMPAT(test_multibytecodec_support.TestBase, unittest.TestCase):
  76.     encoding = 'shift_jis'
  77.     tstring = test_multibytecodec_support.load_teststring('shift_jis')
  78.     codectests = shiftjis_commonenctests + (
  79.         ("\\\x7e", "strict", u"\\\x7e"),
  80.         ("\x81\x5f\x81\x61\x81\x7c", "strict", u"\uff3c\u2016\u2212"),
  81.     )
  82.  
  83. class Test_SJISX0213(test_multibytecodec_support.TestBase, unittest.TestCase):
  84.     encoding = 'shift_jisx0213'
  85.     tstring = test_multibytecodec_support.load_teststring('shift_jisx0213')
  86.     codectests = (
  87.         # invalid bytes
  88.         ("abc\x80\x80\x82\x84", "strict",  None),
  89.         ("abc\xf8", "strict",  None),
  90.         ("abc\x80\x80\x82\x84", "replace", u"abc\ufffd\uff44"),
  91.         ("abc\x80\x80\x82\x84\x88", "replace", u"abc\ufffd\uff44\ufffd"),
  92.         ("abc\x80\x80\x82\x84def", "ignore",  u"abc\uff44def"),
  93.         # sjis vs cp932
  94.         ("\\\x7e", "replace", u"\xa5\u203e"),
  95.         ("\x81\x5f\x81\x61\x81\x7c", "replace", u"\x5c\u2016\u2212"),
  96.     )
  97.     xmlcharnametest = (
  98.         u"\xab\u211c\xbb = \u2329\u1234\u232a",
  99.         "\x85Gℜ\x85Q = ⟨ሴ⟩"
  100.     )
  101.  
  102. def test_main():
  103.     suite = unittest.TestSuite()
  104.     suite.addTest(unittest.makeSuite(Test_CP932))
  105.     suite.addTest(unittest.makeSuite(Test_EUC_JISX0213))
  106.     suite.addTest(unittest.makeSuite(Test_EUC_JP_COMPAT))
  107.     suite.addTest(unittest.makeSuite(Test_SJIS_COMPAT))
  108.     suite.addTest(unittest.makeSuite(Test_SJISX0213))
  109.     test_support.run_suite(suite)
  110.  
  111. if __name__ == "__main__":
  112.     test_main()
  113.